package com.study.bigwork.like.dao;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.Query;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.study.bigwork.entity.Like;

@Repository
public class LikeDao {
	@Resource
	private SessionFactory sessionFactory;
	public List<Like> getLikes(){
		Session session=sessionFactory.getCurrentSession();
		Query query=session.createQuery("from Like");
		List<Like> likes=query.getResultList();
		if(likes!=null) {
			return likes;
		}
		return null;
	}
	

	public void deleteLike(int id) {
		Session session =sessionFactory.getCurrentSession();
		String hql="delete from Like where id=?";
		Query query=session.createQuery(hql);
		query.setParameter(0, id);
		int ret=query.executeUpdate();
		
		
	}
	public void addLike(int userid,int circleid) {
		String hql="insert into Like set userid=? ,circleid=?";
		Session session=sessionFactory.getCurrentSession();
		Query query=session.createQuery(hql);
		query.setParameter(0, userid);
		query.setParameter(1, circleid);
		query.executeUpdate();
	}
	public void changeLikeSize(int circleid,int count) {
		String hql="update into Circle set likesize=? where id=?";
		Session session=sessionFactory.getCurrentSession();
		Query query=session.createQuery(hql);
		query.setParameter(0, count);
		query.setParameter(1, circleid);
		query.executeUpdate();
		
	}
}
